﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace KTV项目
{
    public partial class bianji : Form
    {
        Bestdao dao = new Bestdao();
        public bianji()
        {
            InitializeComponent();
        }
        string lujing;
        private void button2_Click(object sender, EventArgs e)
        {
            //设置歌曲设置时选择的路径位置
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.InitialDirectory = "D:\\Songs";
            ofd.Filter = "mp3|*.mp3|mp4|*.MP4|mpg|*.mpg";
            DialogResult dr = ofd.ShowDialog();
            if (dr==DialogResult.OK)
            {
                //将得到的路径存储在全局变量
                lujing = ofd.FileName;
                //并告诉文本框显示的路径为此值
                this.texlu.Text = lujing;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //将查询到的歌手名称绑定到下拉框中
            string sql = "select singer_name,singer_id from singer_info";
            comgeshou.DataSource = dao.table(sql);
            comgeshou.DisplayMember = "singer_name";
            comgeshou.ValueMember = "singer_id";
        }

        private void bianji_Load(object sender, EventArgs e)
        {
            //将查询到的歌曲类型绑定到下拉框中
            string sql = "select songtype_name,songtype_id from song_type";
            comlei.DataSource = dao.table(sql);
            comlei.DisplayMember = "songtype_name";
            comlei.ValueMember = "songtype_id";
        }

        private void button4_Click(object sender, EventArgs e)
        {
            //执行关闭数据库操作
            this.Close();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            //将窗体获得的歌曲数据存储到数据库中，创建SQL语句
            string sql = string.Format(@"insert song_info values
('{0}', '{1}', {2}, {3}, '{4}',{5})",textname.Text,textsuo.Text,comlei.SelectedIndex+1,comgeshou.SelectedIndex+1,lujing,0);
            int he = dao.query(sql);
            if (he!=0)
            {
                //将窗体的数据存储到数据库中并提示添加成功
                MessageBox.Show("歌曲增加成功","提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                this.Close();
            }
            else
            {
                //否则就提示添加失败
                MessageBox.Show("歌曲增加失败","提示",MessageBoxButtons.OK,MessageBoxIcon.Asterisk);
            }
        }
    }
}
